home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / tests / packers.c < prev   
C/C++ Source or Header  |  1997-08-07  |  60KB  |  1,681 lines

  1. /* packers.c:  Test packing functions
  2.  *
  3.  * Copyright (c) 1997, Kenneth Albanowski
  4.  *
  5.  * This is free software, licensed under the GNU Public License V2.
  6.  * See the file COPYING for details.
  7.  */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "pi-source.h"
  14. #include "pi-socket.h"
  15. #include "pi-memo.h"
  16. #include "pi-address.h"
  17. #include "pi-datebook.h"
  18. #include "pi-todo.h"
  19. #include "pi-dlp.h"
  20. #include "pi-expense.h"
  21. #include "pi-mail.h"
  22.  
  23. unsigned char seed;
  24. char * target;
  25. int targetlen;
  26.  
  27.  
  28. void reset_block(char * buffer, int len)
  29. {
  30.   unsigned int i;
  31.   for(i=0;i<len;i++)
  32.     buffer[i] = (i+seed) & 0xff;
  33. }
  34.  
  35. int check_block(int test, const char * buffer, int len, int start, int count, const char * name)
  36. {
  37.   unsigned int i;
  38.   int fore=0,aft=0;
  39.   for(i=0;i<start;i++)
  40.     if (buffer[i] != (char)((i+seed) & 0xff)) {
  41.       fore = start-i;
  42.       break;
  43.     }
  44.   for(i=start+count;i<len;i++)
  45.     if (buffer[i] != (char)((i+seed) & 0xff)) {
  46.       aft = i-start;
  47.       break;
  48.     }
  49.   if (fore || aft) {
  50.     printf("%d: %s scribbled ", test, name);
  51.     if (fore)
  52.       printf("%d byte(s) before", fore);
  53.     if (fore && aft)
  54.       printf(", and ");
  55.     if (aft)
  56.       printf("%d byte(s) after", aft);
  57.     printf(" the allocated buffer.\n");
  58.     return 1;
  59.   }
  60.   return 0;
  61. }
  62.  
  63. char MemoAppBlock[17*16+10] = "\
  64. \x00\x00\x55\x6e\x66\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  65. \x00\x00\x42\x75\x73\x69\x6e\x65\x73\x73\x00\x00\x00\x00\x00\x00\
  66. \x00\x00\x50\x65\x72\x73\x6f\x6e\x61\x6c\x00\x00\x00\x00\x00\x00\
  67. \x00\x00\x54\x65\x63\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  68. \x00\x00\x54\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  69. \x00\x00\x42\x6f\x6f\x6b\x73\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  70. \x00\x00\x53\x74\x6f\x72\x79\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  71. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  72. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  73. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  74. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  75. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  76. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  77. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  78. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  79. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  80. \x00\x00\x00\x01\x02\x10\x11\x12\x13\x00\x00\x00\x00\x00\x00\x00\
  81. \x00\x00\x13\x00\x00\x00\x00\x00\x01\x00";
  82.  
  83. char MemoRecord[3*16+7] = "\
  84. \x61\x61\x4d\x61\x6b\x65\x66\x69\x6c\x65\x0a\x52\x45\x41\x44\x4d\
  85. \x45\x0a\x6c\x69\x63\x65\x6e\x73\x65\x2e\x74\x65\x72\x6d\x73\x0a\
  86. \x70\x69\x6c\x6f\x74\x6c\x69\x6e\x6b\x2e\x63\x0a\x74\x65\x73\x74\
  87. \x2e\x74\x63\x6c\x2a\x0a\x00";
  88.  
  89. int test_memo() {
  90.   struct MemoAppInfo mai;
  91.   struct Memo m;
  92.   int l;
  93.   int errors=0;
  94.   
  95.   /* Unpacker should return count of bytes used */
  96.   l = unpack_MemoAppInfo(&mai, MemoAppBlock, sizeof(MemoAppBlock)+10);
  97.   if (l != sizeof(MemoAppBlock)) {
  98.     errors++;
  99.     printf("1: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoAppBlock));
  100.   }
  101.  
  102.   /* Unpacker should return count of bytes used */
  103.   l = unpack_MemoAppInfo(&mai, MemoAppBlock, sizeof(MemoAppBlock)+1);
  104.   if (l != sizeof(MemoAppBlock)) {
  105.     errors++;
  106.     printf("2: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoAppBlock));
  107.   }
  108.  
  109.   /* Unpacker should return failure if the block is too small to contain data */
  110.   l = unpack_MemoAppInfo(&mai, MemoAppBlock, sizeof(MemoAppBlock)-10);
  111.   if (l != 0) {
  112.     errors++;
  113.     printf("3: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  114.   }
  115.  
  116.   /* Unpacker should return failure if the block is too small to contain data */
  117.   /* Note: -1 isn't used, because four bytes _can_ be subtracted, to account for
  118.      the new data in OS 2.0 */
  119.   l = unpack_MemoAppInfo(&mai, MemoAppBlock, sizeof(MemoAppBlock)-5);
  120.   if (l != 0) {
  121.     errors++;
  122.     printf("4: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  123.   }
  124.  
  125.   /* Unpacker should return count of bytes used */
  126.   l = unpack_MemoAppInfo(&mai, MemoAppBlock, sizeof(MemoAppBlock));
  127.   if (l != sizeof(MemoAppBlock)) {
  128.     errors++;
  129.     printf("5: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoAppBlock));
  130.   }
  131.   
  132.   if (
  133.      (mai.sortByAlpha == 0) ||
  134.      strcmp(mai.category.name[0],"Unfiled") ||
  135.      strcmp(mai.category.name[1],"Business") ||
  136.      strcmp(mai.category.name[2],"Personal") ||
  137.      strcmp(mai.category.name[3],"Tech") ||
  138.      strcmp(mai.category.name[4],"Test") ||
  139.      strcmp(mai.category.name[5],"Books") ||
  140.      strcmp(mai.category.name[6],"Story") ||
  141.      strcmp(mai.category.name[7],"") ||
  142.      strcmp(mai.category.name[8],"") ||
  143.      strcmp(mai.category.name[9],"") ||
  144.      strcmp(mai.category.name[10],"") ||
  145.      strcmp(mai.category.name[11],"") ||
  146.      strcmp(mai.category.name[12],"") ||
  147.      strcmp(mai.category.name[13],"") ||
  148.      strcmp(mai.category.name[14],"") ||
  149.      strcmp(mai.category.name[15],"") ||
  150.      mai.category.renamed[0] ||
  151.      mai.category.renamed[1] ||
  152.      mai.category.renamed[2] ||
  153.      mai.category.renamed[3] ||
  154.      mai.category.renamed[4] ||
  155.      mai.category.renamed[5] ||
  156.      mai.category.renamed[6] ||
  157.      mai.category.renamed[7] ||
  158.      mai.category.renamed[8] ||
  159.      mai.category.renamed[9] ||
  160.      mai.category.renamed[10] ||
  161.      mai.category.renamed[11] ||
  162.      mai.category.renamed[12] ||
  163.      mai.category.renamed[13] ||
  164.      mai.category.renamed[14] ||
  165.      mai.category.renamed[15] ||
  166.      (mai.category.ID[0] != 0) ||
  167.      (mai.category.ID[1] != 1) ||
  168.      (mai.category.ID[2] != 2) ||
  169.      (mai.category.ID[3] != 16) ||
  170.      (mai.category.ID[4] != 17) ||
  171.      (mai.category.ID[5] != 18) ||
  172.      (mai.category.ID[6] != 19) ||
  173.      (mai.category.ID[7] != 0) ||
  174.      (mai.category.ID[8] != 0) ||
  175.      (mai.category.ID[9] != 0) ||
  176.      (mai.category.ID[10] != 0) ||
  177.      (mai.category.ID[11] != 0) ||
  178.      (mai.category.ID[12] != 0) ||
  179.      (mai.category.ID[13] != 0) ||
  180.      (mai.category.ID[14] != 0) ||
  181.      (mai.category.ID[15] != 0) ||
  182.      (mai.category.lastUniqueID != 19)  ||
  183.      0
  184.      ) {
  185.      errors++;
  186.      printf("6: unpack_MemoAppInfo generated incorrect information\n");
  187.   }
  188.   
  189.   /* Packer should return necessary block length when no buffer is given */
  190.   l = pack_MemoAppInfo(&mai, 0, 0);
  191.   if (l != sizeof(MemoAppBlock)) {
  192.     errors++;
  193.     printf("7: pack_MemoAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MemoAppBlock));
  194.   }
  195.   
  196.   reset_block(target,8192);
  197.  
  198.   /* Packer should not pack when the block length is too small */
  199.   l = pack_MemoAppInfo(&mai, target+128, 1);
  200.   if (l != 0) {
  201.     errors++;
  202.     printf("8: pack_MemoAppInfo packed into too small buffer (got %d)\n", l);
  203.   }
  204.   
  205.   /* Packer should not scribble on memory */
  206.   if (check_block(9, target,8192, 128, 1, "pack_MemoAppInfo"))
  207.     errors++;
  208.  
  209.   reset_block(target,8192);
  210.  
  211.   /* Packer should return length of data written */
  212.   l = pack_MemoAppInfo(&mai, target+128, 8192-256);
  213.   if (l != sizeof(MemoAppBlock)) {
  214.     errors++;
  215.     printf("10: pack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoAppBlock));
  216.   }
  217.  
  218.   /* Packer should not scribble on memory */
  219.   if (check_block(11, target,8192, 128, l, "pack_MemoAppInfo"))
  220.     errors++;
  221.     
  222.   if (memcmp(target+128, MemoAppBlock, sizeof(MemoAppBlock))) {
  223.     errors++;
  224.     printf("12: pack_MemoAppInfo generated incorrect information. Got:\n");
  225.     dumpdata(target+128, l);
  226.     printf(" expected:\n");
  227.     dumpdata(MemoAppBlock, sizeof(MemoAppBlock));
  228.   }
  229.     
  230.   
  231.   /* Unpacker should return count of bytes used */
  232.   l = unpack_Memo(&m, MemoRecord, sizeof(MemoRecord)+10);
  233.   if (l != sizeof(MemoRecord)) {
  234.     errors++;
  235.     printf("13: unpack_Memo returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoRecord));
  236.   }
  237.  
  238.   if (
  239.      (m.text == 0) ||
  240.      strcmp(m.text,"aaMakefile\x0aREADME\x0alicense.terms\x0apilotlink.c\x0atest.tcl*\x0a")
  241.      ) {
  242.      errors++;
  243.      printf("14: unpack_Memo generated incorrect information\n");
  244.   }
  245.   
  246.   /* Packer should return necessary block length when no buffer is given */
  247.   l = pack_Memo(&m, 0, 0);
  248.   if (l != sizeof(MemoRecord)) {
  249.     errors++;
  250.     printf("15: pack_MemoRecord returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MemoRecord));
  251.   }
  252.   
  253.   reset_block(target,8192);
  254.  
  255.   /* Packer should not pack when the block length is too small */
  256.   l = pack_Memo(&m, target+128, 1);
  257.   if (l != 0) {
  258.     errors++;
  259.     printf("16: pack_MemoRecord packed into too small buffer (got %d)\n", l);
  260.   }
  261.   
  262.   /* Packer should not scribble on memory */
  263.   if (check_block(17, target, 8192, 128, 1, "pack_Memo"))
  264.     errors++;
  265.  
  266.   reset_block(target,8192);
  267.  
  268.   /* Packer should return length of data written */
  269.   l = pack_Memo(&m, target+128, 8192-256);
  270.   if (l != sizeof(MemoRecord)) {
  271.     errors++;
  272.     printf("18: pack_MemoRecord returned incorrect length (got %d, expected %d)\n", l, sizeof(MemoRecord));
  273.   }
  274.  
  275.   /* Packer should not scribble on memory */
  276.   if (check_block(19, target,8192, 128, l, "pack_Memo"))
  277.     errors++;
  278.     
  279.   if (memcmp(target+128, MemoRecord, sizeof(MemoRecord))) {
  280.     errors++;
  281.     printf("20: pack_Memo generated incorrect information. Got:\n");
  282.     dumpdata(target+128, l);
  283.     printf(" expected:\n");
  284.     dumpdata(MemoRecord, sizeof(MemoRecord));
  285.   }
  286.     
  287.   printf("Memo packers test completed with %d error(s).\n", errors);
  288.   
  289.   return errors;
  290. }
  291.  
  292. char AddressAppBlock[39*16+14] = "\
  293. \x00\x10\x55\x6e\x66\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  294. \x00\x00\x42\x75\x73\x69\x6e\x65\x73\x73\x00\x00\x00\x00\x00\x00\
  295. \x00\x00\x50\x65\x72\x73\x6f\x6e\x61\x6c\x00\x00\x00\x00\x00\x00\
  296. \x00\x00\x51\x75\x69\x63\x6b\x4c\x69\x73\x74\x00\x00\x00\x00\x00\
  297. \x00\x00\x46\x6f\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  298. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  299. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  300. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  301. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  302. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  303. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  304. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  305. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  306. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  307. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  308. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  309. \x00\x00\x00\x01\x02\x03\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  310. \x00\x00\x11\x00\x00\x00\x00\x00\x0e\x00\x4c\x61\x73\x74\x20\x6e\
  311. \x61\x6d\x65\x00\x00\x00\x00\x00\x00\x00\x46\x69\x72\x73\x74\x20\
  312. \x6e\x61\x6d\x65\x00\x00\x00\x00\x00\x00\x43\x6f\x6d\x70\x61\x6e\
  313. \x79\x00\x00\x00\x00\x00\x00\x00\x00\x00\x57\x6f\x72\x6b\x00\x00\
  314. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x48\x6f\x6d\x65\x00\x00\
  315. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x46\x61\x78\x00\x00\x00\
  316. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4f\x74\x68\x65\x72\x00\
  317. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x45\x2d\x6d\x61\x69\x6c\
  318. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x41\x64\x64\x72\x65\x73\
  319. \x73\x00\x00\x00\x00\x00\x00\x00\x00\x00\x43\x69\x74\x79\x00\x00\
  320. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x53\x74\x61\x74\x65\x00\
  321. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5a\x69\x70\x20\x43\x6f\
  322. \x64\x65\x00\x00\x00\x00\x00\x00\x00\x00\x43\x6f\x75\x6e\x74\x72\
  323. \x79\x00\x00\x00\x00\x00\x00\x00\x00\x00\x54\x69\x74\x6c\x65\x00\
  324. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x43\x75\x73\x74\x6f\x6d\
  325. \x20\x31\x00\x00\x00\x00\x00\x00\x00\x00\x43\x75\x73\x74\x6f\x6d\
  326. \x20\x32\x00\x00\x00\x00\x00\x00\x00\x00\x43\x75\x73\x74\x6f\x6d\
  327. \x20\x33\x00\x00\x00\x00\x00\x00\x00\x00\x43\x75\x73\x74\x6f\x6d\
  328. \x20\x34\x00\x00\x00\x00\x00\x00\x00\x00\x4e\x6f\x74\x65\x00\x00\
  329. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4d\x61\x69\x6e\x00\x00\
  330. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x61\x67\x65\x72\x00\
  331. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4d\x6f\x62\x69\x6c\x65\
  332. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00";
  333.  
  334. char AddressRecord[2*16+12] = "\
  335. \x00\x14\x32\x10\x00\x04\x41\x03\x00\x53\x68\x61\x77\x00\x42\x65\
  336. \x72\x6e\x61\x72\x64\x00\x4e\x6f\x6e\x65\x20\x6b\x6e\x6f\x77\x6e\
  337. \x00\x43\x31\x00\x41\x20\x6e\x6f\x74\x65\x2e\x00";
  338.  
  339. int test_address() {
  340.   struct AddressAppInfo mai;
  341.   struct Address m;
  342.   int l;
  343.   int errors=0;
  344.   
  345.   /* Unpacker should return count of bytes used */
  346.   l = unpack_AddressAppInfo(&mai, AddressAppBlock, sizeof(AddressAppBlock)+10);
  347.   if (l != sizeof(AddressAppBlock)) {
  348.     errors++;
  349.     printf("1: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressAppBlock));
  350.   }
  351.  
  352.   /* Unpacker should return count of bytes used */
  353.   l = unpack_AddressAppInfo(&mai, AddressAppBlock, sizeof(AddressAppBlock)+1);
  354.   if (l != sizeof(AddressAppBlock)) {
  355.     errors++;
  356.     printf("2: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressAppBlock));
  357.   }
  358.  
  359.   /* Unpacker should return failure if the block is too small to contain data */
  360.   l = unpack_AddressAppInfo(&mai, AddressAppBlock, sizeof(AddressAppBlock)-10);
  361.   if (l != 0) {
  362.     errors++;
  363.     printf("3: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  364.   }
  365.  
  366.   /* Unpacker should return failure if the block is too small to contain data */
  367.   l = unpack_AddressAppInfo(&mai, AddressAppBlock, sizeof(AddressAppBlock)-1);
  368.   if (l != 0) {
  369.     errors++;
  370.     printf("4: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  371.   }
  372.  
  373.   /* Unpacker should return count of bytes used */
  374.   l = unpack_AddressAppInfo(&mai, AddressAppBlock, sizeof(AddressAppBlock));
  375.   if (l != sizeof(AddressAppBlock)) {
  376.     errors++;
  377.     printf("5: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressAppBlock));
  378.   }
  379.   
  380.   if (
  381.      strcmp(mai.category.name[0],"Unfiled") ||
  382.      strcmp(mai.category.name[1],"Business") ||
  383.      strcmp(mai.category.name[2],"Personal") ||
  384.      strcmp(mai.category.name[3],"QuickList") ||
  385.      strcmp(mai.category.name[4],"Foo") ||
  386.      strcmp(mai.category.name[5],"") ||
  387.      strcmp(mai.category.name[6],"") ||
  388.      strcmp(mai.category.name[7],"") ||
  389.      strcmp(mai.category.name[8],"") ||
  390.      strcmp(mai.category.name[9],"") ||
  391.      strcmp(mai.category.name[10],"") ||
  392.      strcmp(mai.category.name[11],"") ||
  393.      strcmp(mai.category.name[12],"") ||
  394.      strcmp(mai.category.name[13],"") ||
  395.      strcmp(mai.category.name[14],"") ||
  396.      strcmp(mai.category.name[15],"") ||
  397.      mai.category.renamed[0] ||
  398.      mai.category.renamed[1] ||
  399.      mai.category.renamed[2] ||
  400.      mai.category.renamed[3] ||
  401.      (!mai.category.renamed[4]) ||
  402.      mai.category.renamed[5] ||
  403.      mai.category.renamed[6] ||
  404.      mai.category.renamed[7] ||
  405.      mai.category.renamed[8] ||
  406.      mai.category.renamed[9] ||
  407.      mai.category.renamed[10] ||
  408.      mai.category.renamed[11] ||
  409.      mai.category.renamed[12] ||
  410.      mai.category.renamed[13] ||
  411.      mai.category.renamed[14] ||
  412.      mai.category.renamed[15] ||
  413.      (mai.category.ID[0] != 0) ||
  414.      (mai.category.ID[1] != 1) ||
  415.      (mai.category.ID[2] != 2) ||
  416.      (mai.category.ID[3] != 3) ||
  417.      (mai.category.ID[4] != 17) ||
  418.      (mai.category.ID[5] != 0) ||
  419.      (mai.category.ID[6] != 0) ||
  420.      (mai.category.ID[7] != 0) ||
  421.      (mai.category.ID[8] != 0) ||
  422.      (mai.category.ID[9] != 0) ||
  423.      (mai.category.ID[10] != 0) ||
  424.      (mai.category.ID[11] != 0) ||
  425.      (mai.category.ID[12] != 0) ||
  426.      (mai.category.ID[13] != 0) ||
  427.      (mai.category.ID[14] != 0) ||
  428.      (mai.category.ID[15] != 0) ||
  429.      (mai.category.lastUniqueID != 17)  ||
  430.      0
  431.      ) {
  432.      errors++;
  433.      printf("6: unpack_AddressAppInfo generated incorrect information\n");
  434.   }
  435.   
  436.   /* Packer should return necessary block length when no buffer is given */
  437.   l = pack_AddressAppInfo(&mai, 0, 0);
  438.   if (l != sizeof(AddressAppBlock)) {
  439.     errors++;
  440.     printf("7: pack_AddressAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(AddressAppBlock));
  441.   }
  442.   
  443.   reset_block(target,8192);
  444.  
  445.   /* Packer should not pack when the block length is too small */
  446.   l = pack_AddressAppInfo(&mai, target+128, 1);
  447.   if (l != 0) {
  448.     errors++;
  449.     printf("8: pack_AddressAppInfo packed into too small buffer (got %d)\n", l);
  450.   }
  451.   
  452.   /* Packer should not scribble on memory */
  453.   if (check_block(9, target,8192, 128, 1, "pack_AddressAppInfo"))
  454.     errors++;
  455.  
  456.   reset_block(target,8192);
  457.  
  458.   /* Packer should return length of data written */
  459.   l = pack_AddressAppInfo(&mai, target+128, 8192-256);
  460.   if (l != sizeof(AddressAppBlock)) {
  461.     errors++;
  462.     printf("10: pack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressAppBlock));
  463.   }
  464.  
  465.   /* Packer should not scribble on memory */
  466.   if (check_block(11, target,8192, 128, l, "pack_AddressAppInfo"))
  467.     errors++;
  468.     
  469.   if (memcmp(target+128, AddressAppBlock, sizeof(AddressAppBlock))) {
  470.     errors++;
  471.     printf("12: pack_AddressAppInfo generated incorrect information. Got:\n");
  472.     dumpdata(target+128, l);
  473.     printf(" expected:\n");
  474.     dumpdata(AddressAppBlock, sizeof(AddressAppBlock));
  475.   }
  476.     
  477.   
  478.   /* Unpacker should return count of bytes used */
  479.   l = unpack_Address(&m, AddressRecord, sizeof(AddressRecord)+10);
  480.   if (l != sizeof(AddressRecord)) {
  481.     errors++;
  482.     printf("13: unpack_Address returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressRecord));
  483.   }
  484.  
  485.   if (
  486.      (m.phoneLabel[0] != 0) ||
  487.      (m.phoneLabel[1] != 1) ||
  488.      (m.phoneLabel[2] != 2) ||
  489.      (m.phoneLabel[3] != 3) ||
  490.      (m.phoneLabel[4] != 4) ||
  491.      strcmp(m.entry[0],"Shaw") ||
  492.      strcmp(m.entry[1],"Bernard") ||
  493.      m.entry[2] ||
  494.      m.entry[3] ||
  495.      strcmp(m.entry[8],"None known") ||
  496.      strcmp(m.entry[14],"C1") ||
  497.      (m.showPhone != 1) ||
  498.      0
  499.      ) {
  500.      errors++;
  501.      printf("14: unpack_Address generated incorrect information\n");
  502.   }
  503.   
  504.   /* Packer should return necessary block length when no buffer is given */
  505.   l = pack_Address(&m, 0, 0);
  506.   if (l != sizeof(AddressRecord)) {
  507.     errors++;
  508.     printf("15: pack_Address returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(AddressRecord));
  509.   }
  510.   
  511.   reset_block(target,8192);
  512.  
  513.   /* Packer should not pack when the block length is too small */
  514.   l = pack_Address(&m, target+128, 1);
  515.   if (l != 0) {
  516.     errors++;
  517.     printf("16: pack_Address packed into too small buffer (got %d)\n", l);
  518.   }
  519.   
  520.   /* Packer should not scribble on memory */
  521.   if (check_block(17, target, 8192, 128, 1, "pack_Address"))
  522.     errors++;
  523.  
  524.   reset_block(target,8192);
  525.  
  526.   /* Packer should return length of data written */
  527.   l = pack_Address(&m, target+128, 8192-256);
  528.   if (l != sizeof(AddressRecord)) {
  529.     errors++;
  530.     printf("18: pack_Address returned incorrect length (got %d, expected %d)\n", l, sizeof(AddressRecord));
  531.   }
  532.  
  533.   /* Packer should not scribble on memory */
  534.   if (check_block(19, target,8192, 128, l, "pack_Address"))
  535.     errors++;
  536.     
  537.   if (memcmp(target+128, AddressRecord, sizeof(AddressRecord))) {
  538.     errors++;
  539.     printf("20: pack_Address generated incorrect information. Got:\n");
  540.     dumpdata(target+128, l);
  541.     printf(" expected:\n");
  542.     dumpdata(AddressRecord, sizeof(AddressRecord));
  543.   }
  544.     
  545.   printf("Address packers test completed with %d error(s).\n", errors);
  546.   
  547.   return errors;
  548. }
  549.  
  550. char AppointmentAppBlock[17*16+8] = "\
  551. \x00\x00\x55\x6e\x66\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  552. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  553. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  554. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  555. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  556. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  557. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  558. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  559. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  560. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  561. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  562. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  563. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  564. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  565. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  566. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  567. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  568. \x00\x00\x00\x00\x00\x00\x00\x00";
  569.  
  570. /* Note: Bytes seven and seventeen ares undefined by the Pilot code,
  571.    and thus have a floating value. This sample record has
  572.    been altered to make theses bytes zero, to match what our
  573.    packing code generates.  */
  574. char AppointmentRecord[2*16+3] = "\
  575. \x09\x00\x0d\x28\xbb\x02\x7c\x00\x1d\x02\x02\x00\xbd\x24\x02\x55\
  576. \x00\x00\x00\x01\xbb\x0c\x47\x65\x6f\x72\x67\x65\x00\x4e\x6f\x74\
  577. \x65\x21\x00";
  578.  
  579.  
  580. int test_appointment() {
  581.   struct AppointmentAppInfo mai;
  582.   struct Appointment m;
  583.   int l;
  584.   int errors=0;
  585.   
  586.   /* Unpacker should return count of bytes used */
  587.   l = unpack_AppointmentAppInfo(&mai, AppointmentAppBlock, sizeof(AppointmentAppBlock)+10);
  588.   if (l != sizeof(AppointmentAppBlock)) {
  589.     errors++;
  590.     printf("1: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentAppBlock));
  591.   }
  592.  
  593.   /* Unpacker should return count of bytes used */
  594.   l = unpack_AppointmentAppInfo(&mai, AppointmentAppBlock, sizeof(AppointmentAppBlock)+1);
  595.   if (l != sizeof(AppointmentAppBlock)) {
  596.     errors++;
  597.     printf("2: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentAppBlock));
  598.   }
  599.  
  600.   /* Unpacker should return failure if the block is too small to contain data */
  601.   l = unpack_AppointmentAppInfo(&mai, AppointmentAppBlock, sizeof(AppointmentAppBlock)-10);
  602.   if (l != 0) {
  603.     errors++;
  604.     printf("3: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  605.   }
  606.  
  607.   /* Unpacker should return failure if the block is too small to contain data */
  608.   l = unpack_AppointmentAppInfo(&mai, AppointmentAppBlock, sizeof(AppointmentAppBlock)-1);
  609.   if (l != 0) {
  610.     errors++;
  611.     printf("4: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  612.   }
  613.  
  614.   /* Unpacker should return count of bytes used */
  615.   l = unpack_AppointmentAppInfo(&mai, AppointmentAppBlock, sizeof(AppointmentAppBlock));
  616.   if (l != sizeof(AppointmentAppBlock)) {
  617.     errors++;
  618.     printf("5: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentAppBlock));
  619.   }
  620.  
  621.   if (
  622. /*     strcmp(mai.category.name[0],"Unfiled") ||
  623.      strcmp(mai.category.name[1],"Business") ||
  624.      strcmp(mai.category.name[2],"Personal") ||
  625.      strcmp(mai.category.name[3],"QuickList") ||
  626.      strcmp(mai.category.name[4],"Foo") ||
  627.      strcmp(mai.category.name[5],"") ||
  628.      strcmp(mai.category.name[6],"") ||
  629.      strcmp(mai.category.name[7],"") ||
  630.      strcmp(mai.category.name[8],"") ||
  631.      strcmp(mai.category.name[9],"") ||
  632.      strcmp(mai.category.name[10],"") ||
  633.      strcmp(mai.category.name[11],"") ||
  634.      strcmp(mai.category.name[12],"") ||
  635.      strcmp(mai.category.name[13],"") ||
  636.      strcmp(mai.category.name[14],"") ||
  637.      strcmp(mai.category.name[15],"") ||
  638.      mai.category.renamed[0] ||
  639.      mai.category.renamed[1] ||
  640.      mai.category.renamed[2] ||
  641.      mai.category.renamed[3] ||
  642.      (!mai.category.renamed[4]) ||
  643.      mai.category.renamed[5] ||
  644.      mai.category.renamed[6] ||
  645.      mai.category.renamed[7] ||
  646.      mai.category.renamed[8] ||
  647.      mai.category.renamed[9] ||
  648.      mai.category.renamed[10] ||
  649.      mai.category.renamed[11] ||
  650.      mai.category.renamed[12] ||
  651.      mai.category.renamed[13] ||
  652.      mai.category.renamed[14] ||
  653.      mai.category.renamed[15] ||
  654.      (mai.category.ID[0] != 0) ||
  655.      (mai.category.ID[1] != 1) ||
  656.      (mai.category.ID[2] != 2) ||
  657.      (mai.category.ID[3] != 3) ||
  658.      (mai.category.ID[4] != 17) ||
  659.      (mai.category.ID[5] != 0) ||
  660.      (mai.category.ID[6] != 0) ||
  661.      (mai.category.ID[7] != 0) ||
  662.      (mai.category.ID[8] != 0) ||
  663.      (mai.category.ID[9] != 0) ||
  664.      (mai.category.ID[10] != 0) ||
  665.      (mai.category.ID[11] != 0) ||
  666.      (mai.category.ID[12] != 0) ||
  667.      (mai.category.ID[13] != 0) ||
  668.      (mai.category.ID[14] != 0) ||
  669.      (mai.category.ID[15] != 0) ||
  670.      (mai.category.lastUniqueID != 17)  ||*/
  671.      0
  672.      ) {
  673.      errors++;
  674.      printf("6: unpack_AppointmentAppInfo generated incorrect information\n");
  675.   }
  676.   
  677.   /* Packer should return necessary block length when no buffer is given */
  678.   l = pack_AppointmentAppInfo(&mai, 0, 0);
  679.   if (l != sizeof(AppointmentAppBlock)) {
  680.     errors++;
  681.     printf("7: pack_AppointmentAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(AppointmentAppBlock));
  682.   }
  683.   
  684.   reset_block(target,8192);
  685.  
  686.   /* Packer should not pack when the block length is too small */
  687.   l = pack_AppointmentAppInfo(&mai, target+128, 1);
  688.   if (l != 0) {
  689.     errors++;
  690.     printf("8: pack_AppointmentAppInfo packed into too small buffer (got %d)\n", l);
  691.   }
  692.   
  693.   /* Packer should not scribble on memory */
  694.   if (check_block(9, target,8192, 128, 1, "pack_AppointmentAppInfo"))
  695.     errors++;
  696.  
  697.   reset_block(target,8192);
  698.  
  699.   /* Packer should return length of data written */
  700.   l = pack_AppointmentAppInfo(&mai, target+128, 8192-256);
  701.   if (l != sizeof(AppointmentAppBlock)) {
  702.     errors++;
  703.     printf("10: pack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentAppBlock));
  704.   }
  705.  
  706.   /* Packer should not scribble on memory */
  707.   if (check_block(11, target,8192, 128, l, "pack_AppointmentAppInfo"))
  708.     errors++;
  709.     
  710.   if (memcmp(target+128, AppointmentAppBlock, sizeof(AppointmentAppBlock))) {
  711.     errors++;
  712.     printf("12: pack_AppointmentAppInfo generated incorrect information. Got:\n");
  713.     dumpdata(target+128, l);
  714.     printf(" expected:\n");
  715.     dumpdata(AppointmentAppBlock, sizeof(AppointmentAppBlock));
  716.   }
  717.     
  718.   
  719.   /* Unpacker should return count of bytes used */
  720.   l = unpack_Appointment(&m, AppointmentRecord, sizeof(AppointmentRecord)+10);
  721.   if (l != sizeof(AppointmentRecord)) {
  722.     errors++;
  723.     printf("13: unpack_Appointment returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentRecord));
  724.   }
  725.  
  726.   if (
  727. /*     (m.phonelabel[0] != 0) ||
  728.      (m.phonelabel[1] != 1) ||
  729.      (m.phonelabel[2] != 2) ||
  730.      (m.phonelabel[3] != 3) ||
  731.      (m.phonelabel[4] != 4) ||
  732.      strcmp(m.entry[0],"Shaw") ||
  733.      strcmp(m.entry[1],"Bernard") ||
  734.      m.entry[2] ||
  735.      m.entry[3] ||
  736.      strcmp(m.entry[8],"None known") ||
  737.      strcmp(m.entry[14],"C1") ||
  738.      (m.whichphone != 1) ||*/
  739.      0
  740.      ) {
  741.      errors++;
  742.      printf("14: unpack_Appointment generated incorrect information\n");
  743.   }
  744.   
  745.   /* Packer should return necessary block length when no buffer is given */
  746.   l = pack_Appointment(&m, 0, 0);
  747.   if (l != sizeof(AppointmentRecord)) {
  748.     errors++;
  749.     printf("15: pack_Appointment returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(AppointmentRecord));
  750.   }
  751.   
  752.   reset_block(target,8192);
  753.  
  754.   /* Packer should not pack when the block length is too small */
  755.   l = pack_Appointment(&m, target+128, 1);
  756.   if (l != 0) {
  757.     errors++;
  758.     printf("16: pack_Appointment packed into too small buffer (got %d)\n", l);
  759.   }
  760.   
  761.   /* Packer should not scribble on memory */
  762.   if (check_block(17, target, 8192, 128, 1, "pack_Appointment"))
  763.     errors++;
  764.  
  765.   reset_block(target,8192);
  766.  
  767.   /* Packer should return length of data written */
  768.   l = pack_Appointment(&m, target+128, 8192-256);
  769.   if (l != sizeof(AppointmentRecord)) {
  770.     errors++;
  771.     printf("18: pack_Appointment returned incorrect length (got %d, expected %d)\n", l, sizeof(AppointmentRecord));
  772.   }
  773.  
  774.   /* Packer should not scribble on memory */
  775.   if (check_block(19, target,8192, 128, l, "pack_Appointment"))
  776.     errors++;
  777.     
  778.   if (memcmp(target+128, AppointmentRecord, sizeof(AppointmentRecord))) {
  779.     errors++;
  780.     printf("20: pack_Appointment generated incorrect information. Got:\n");
  781.     dumpdata(target+128, l);
  782.     printf(" expected:\n");
  783.     dumpdata(AppointmentRecord, sizeof(AppointmentRecord));
  784.   }
  785.     
  786.   printf("Appointment packers test completed with %d error(s).\n", errors);
  787.   
  788.   return errors;
  789. }
  790.  
  791. char ToDoAppBlock[17*16+10] = "\
  792. \x00\x08\x55\x6e\x66\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  793. \x00\x00\x42\x75\x73\x69\x6e\x65\x73\x73\x00\x00\x00\x00\x00\x00\
  794. \x00\x00\x50\x65\x72\x73\x6f\x6e\x61\x6c\x00\x00\x00\x00\x00\x00\
  795. \x00\x00\x46\x6f\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  796. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  797. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  798. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  799. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  800. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  801. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  802. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  803. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  804. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  805. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  806. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  807. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  808. \x00\x00\x00\x01\x02\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  809. \x00\x00\x11\x00\x00\x00\xff\xff\x01\x00";
  810.  
  811. char ToDoRecord[1*16+1] = "\
  812. \xbb\x09\x05\x54\x6f\x64\x6f\x33\x00\x41\x20\x6e\x6f\x74\x65\x2e\
  813. \x00";
  814.  
  815. int test_todo() {
  816.   struct ToDoAppInfo mai;
  817.   struct ToDo m;
  818.   int l;
  819.   int errors=0;
  820.   
  821.   /* Unpacker should return count of bytes used */
  822.   l = unpack_ToDoAppInfo(&mai, ToDoAppBlock, sizeof(ToDoAppBlock)+10);
  823.   if (l != sizeof(ToDoAppBlock)) {
  824.     errors++;
  825.     printf("1: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoAppBlock));
  826.   }
  827.  
  828.   /* Unpacker should return count of bytes used */
  829.   l = unpack_ToDoAppInfo(&mai, ToDoAppBlock, sizeof(ToDoAppBlock)+1);
  830.   if (l != sizeof(ToDoAppBlock)) {
  831.     errors++;
  832.     printf("2: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoAppBlock));
  833.   }
  834.  
  835.   /* Unpacker should return failure if the block is too small to contain data */
  836.   l = unpack_ToDoAppInfo(&mai, ToDoAppBlock, sizeof(ToDoAppBlock)-10);
  837.   if (l != 0) {
  838.     errors++;
  839.     printf("3: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  840.   }
  841.  
  842.   /* Unpacker should return failure if the block is too small to contain data */
  843.   l = unpack_ToDoAppInfo(&mai, ToDoAppBlock, sizeof(ToDoAppBlock)-1);
  844.   if (l != 0) {
  845.     errors++;
  846.     printf("4: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  847.   }
  848.  
  849.   /* Unpacker should return count of bytes used */
  850.   l = unpack_ToDoAppInfo(&mai, ToDoAppBlock, sizeof(ToDoAppBlock));
  851.   if (l != sizeof(ToDoAppBlock)) {
  852.     errors++;
  853.     printf("5: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoAppBlock));
  854.   }
  855.  
  856.   if (
  857. /*     strcmp(mai.category.name[0],"Unfiled") ||
  858.      strcmp(mai.category.name[1],"Business") ||
  859.      strcmp(mai.category.name[2],"Personal") ||
  860.      strcmp(mai.category.name[3],"QuickList") ||
  861.      strcmp(mai.category.name[4],"Foo") ||
  862.      strcmp(mai.category.name[5],"") ||
  863.      strcmp(mai.category.name[6],"") ||
  864.      strcmp(mai.category.name[7],"") ||
  865.      strcmp(mai.category.name[8],"") ||
  866.      strcmp(mai.category.name[9],"") ||
  867.      strcmp(mai.category.name[10],"") ||
  868.      strcmp(mai.category.name[11],"") ||
  869.      strcmp(mai.category.name[12],"") ||
  870.      strcmp(mai.category.name[13],"") ||
  871.      strcmp(mai.category.name[14],"") ||
  872.      strcmp(mai.category.name[15],"") ||
  873.      mai.category.renamed[0] ||
  874.      mai.category.renamed[1] ||
  875.      mai.category.renamed[2] ||
  876.      mai.category.renamed[3] ||
  877.      (!mai.category.renamed[4]) ||
  878.      mai.category.renamed[5] ||
  879.      mai.category.renamed[6] ||
  880.      mai.category.renamed[7] ||
  881.      mai.category.renamed[8] ||
  882.      mai.category.renamed[9] ||
  883.      mai.category.renamed[10] ||
  884.      mai.category.renamed[11] ||
  885.      mai.category.renamed[12] ||
  886.      mai.category.renamed[13] ||
  887.      mai.category.renamed[14] ||
  888.      mai.category.renamed[15] ||
  889.      (mai.category.ID[0] != 0) ||
  890.      (mai.category.ID[1] != 1) ||
  891.      (mai.category.ID[2] != 2) ||
  892.      (mai.category.ID[3] != 3) ||
  893.      (mai.category.ID[4] != 17) ||
  894.      (mai.category.ID[5] != 0) ||
  895.      (mai.category.ID[6] != 0) ||
  896.      (mai.category.ID[7] != 0) ||
  897.      (mai.category.ID[8] != 0) ||
  898.      (mai.category.ID[9] != 0) ||
  899.      (mai.category.ID[10] != 0) ||
  900.      (mai.category.ID[11] != 0) ||
  901.      (mai.category.ID[12] != 0) ||
  902.      (mai.category.ID[13] != 0) ||
  903.      (mai.category.ID[14] != 0) ||
  904.      (mai.category.ID[15] != 0) ||
  905.      (mai.category.lastUniqueID != 17)  ||*/
  906.      0
  907.      ) {
  908.      errors++;
  909.      printf("6: unpack_ToDoAppInfo generated incorrect information\n");
  910.   }
  911.   
  912.   /* Packer should return necessary block length when no buffer is given */
  913.   l = pack_ToDoAppInfo(&mai, 0, 0);
  914.   if (l != sizeof(ToDoAppBlock)) {
  915.     errors++;
  916.     printf("7: pack_ToDoAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(ToDoAppBlock));
  917.   }
  918.   
  919.   reset_block(target,8192);
  920.  
  921.   /* Packer should not pack when the block length is too small */
  922.   l = pack_ToDoAppInfo(&mai, target+128, 1);
  923.   if (l != 0) {
  924.     errors++;
  925.     printf("8: pack_ToDoAppInfo packed into too small buffer (got %d)\n", l);
  926.   }
  927.   
  928.   /* Packer should not scribble on memory */
  929.   if (check_block(9, target,8192, 128, 1, "pack_ToDoAppInfo"))
  930.     errors++;
  931.  
  932.   reset_block(target,8192);
  933.  
  934.   /* Packer should return length of data written */
  935.   l = pack_ToDoAppInfo(&mai, target+128, 8192-256);
  936.   if (l != sizeof(ToDoAppBlock)) {
  937.     errors++;
  938.     printf("10: pack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoAppBlock));
  939.   }
  940.  
  941.   /* Packer should not scribble on memory */
  942.   if (check_block(11, target,8192, 128, l, "pack_ToDoAppInfo"))
  943.     errors++;
  944.     
  945.   if (memcmp(target+128, ToDoAppBlock, sizeof(ToDoAppBlock))) {
  946.     errors++;
  947.     printf("12: pack_ToDoAppInfo generated incorrect information. Got:\n");
  948.     dumpdata(target+128, l);
  949.     printf(" expected:\n");
  950.     dumpdata(ToDoAppBlock, sizeof(ToDoAppBlock));
  951.   }
  952.     
  953.   
  954.   /* Unpacker should return count of bytes used */
  955.   l = unpack_ToDo(&m, ToDoRecord, sizeof(ToDoRecord)+10);
  956.   if (l != sizeof(ToDoRecord)) {
  957.     errors++;
  958.     printf("13: unpack_ToDo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoRecord));
  959.   }
  960.  
  961.   if (
  962. /*     (m.phonelabel[0] != 0) ||
  963.      (m.phonelabel[1] != 1) ||
  964.      (m.phonelabel[2] != 2) ||
  965.      (m.phonelabel[3] != 3) ||
  966.      (m.phonelabel[4] != 4) ||
  967.      strcmp(m.entry[0],"Shaw") ||
  968.      strcmp(m.entry[1],"Bernard") ||
  969.      m.entry[2] ||
  970.      m.entry[3] ||
  971.      strcmp(m.entry[8],"None known") ||
  972.      strcmp(m.entry[14],"C1") ||
  973.      (m.whichphone != 1) ||*/
  974.      0
  975.      ) {
  976.      errors++;
  977.      printf("14: unpack_ToDo generated incorrect information\n");
  978.   }
  979.   
  980.   /* Packer should return necessary block length when no buffer is given */
  981.   l = pack_ToDo(&m, 0, 0);
  982.   if (l != sizeof(ToDoRecord)) {
  983.     errors++;
  984.     printf("15: pack_ToDo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(ToDoRecord));
  985.   }
  986.   
  987.   reset_block(target,8192);
  988.  
  989.   /* Packer should not pack when the block length is too small */
  990.   l = pack_ToDo(&m, target+128, 1);
  991.   if (l != 0) {
  992.     errors++;
  993.     printf("16: pack_ToDo packed into too small buffer (got %d)\n", l);
  994.   }
  995.   
  996.   /* Packer should not scribble on memory */
  997.   if (check_block(17, target, 8192, 128, 1, "pack_ToDo"))
  998.     errors++;
  999.  
  1000.   reset_block(target,8192);
  1001.  
  1002.   /* Packer should return length of data written */
  1003.   l = pack_ToDo(&m, target+128, 8192-256);
  1004.   if (l != sizeof(ToDoRecord)) {
  1005.     errors++;
  1006.     printf("18: pack_ToDo returned incorrect length (got %d, expected %d)\n", l, sizeof(ToDoRecord));
  1007.   }
  1008.  
  1009.   /* Packer should not scribble on memory */
  1010.   if (check_block(19, target,8192, 128, l, "pack_ToDo"))
  1011.     errors++;
  1012.     
  1013.   if (memcmp(target+128, ToDoRecord, sizeof(ToDoRecord))) {
  1014.     errors++;
  1015.     printf("20: pack_ToDo generated incorrect information. Got:\n");
  1016.     dumpdata(target+128, l);
  1017.     printf(" expected:\n");
  1018.     dumpdata(ToDoRecord, sizeof(ToDoRecord));
  1019.   }
  1020.     
  1021.   printf("ToDo packers test completed with %d error(s).\n", errors);
  1022.   
  1023.   return errors;
  1024. }
  1025.  
  1026. char ExpenseAppBlock[24*16+8] = "\
  1027. \x00\x00\x55\x6e\x66\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  1028. \x00\x00\x4e\x65\x77\x20\x59\x6f\x72\x6b\x00\x00\x00\x00\x00\x00\
  1029. \x00\x00\x50\x61\x72\x69\x73\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1030. \x00\x00\x45\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1031. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1032. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1033. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1034. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1035. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1036. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1037. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1038. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1039. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1040. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1041. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1042. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1043. \x00\x00\x00\x01\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1044. \x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1045. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1046. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1047. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1048. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1049. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1050. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1051. \x00\x00\x00\x00\x00\x00\x00\x00";
  1052.  
  1053. /* Byte five is floating */
  1054. char ExpenseRecord[1*16+14] = "\
  1055. \xbb\x2a\x09\x01\x08\x00\x32\x39\x2e\x37\x32\x00\x55\x00\x43\x00\
  1056. \x41\x74\x74\x00\x54\x68\x65\x20\x6e\x6f\x74\x65\x2e\x00";
  1057.  
  1058.  
  1059. int test_expense() {
  1060.   struct ExpenseAppInfo mai;
  1061.   struct Expense m;
  1062.   int l;
  1063.   int errors=0;
  1064.   
  1065.   /* Unpacker should return count of bytes used */
  1066.   l = unpack_ExpenseAppInfo(&mai, ExpenseAppBlock, sizeof(ExpenseAppBlock)+10);
  1067.   if (l != sizeof(ExpenseAppBlock)) {
  1068.     errors++;
  1069.     printf("1: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseAppBlock));
  1070.   }
  1071.  
  1072.   /* Unpacker should return count of bytes used */
  1073.   l = unpack_ExpenseAppInfo(&mai, ExpenseAppBlock, sizeof(ExpenseAppBlock)+1);
  1074.   if (l != sizeof(ExpenseAppBlock)) {
  1075.     errors++;
  1076.     printf("2: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseAppBlock));
  1077.   }
  1078.  
  1079.   /* Unpacker should return failure if the block is too small to contain data */
  1080.   /*l = unpack_ExpenseAppInfo(&mai, ExpenseAppBlock, sizeof(ExpenseAppBlock)-10);
  1081.   if (l != 0) {
  1082.     errors++;
  1083.     printf("x: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  1084.   }*/
  1085.  
  1086.   /* Unpacker should return count of bytes used */
  1087.   l = unpack_ExpenseAppInfo(&mai, ExpenseAppBlock, sizeof(ExpenseAppBlock));
  1088.   if (l != sizeof(ExpenseAppBlock)) {
  1089.     errors++;
  1090.     printf("3: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseAppBlock));
  1091.   }
  1092.  
  1093.   
  1094.   if (
  1095. /*     strcmp(mai.category.name[0],"Unfiled") ||
  1096.      strcmp(mai.category.name[1],"Business") ||
  1097.      strcmp(mai.category.name[2],"Personal") ||
  1098.      strcmp(mai.category.name[3],"QuickList") ||
  1099.      strcmp(mai.category.name[4],"Foo") ||
  1100.      strcmp(mai.category.name[5],"") ||
  1101.      strcmp(mai.category.name[6],"") ||
  1102.      strcmp(mai.category.name[7],"") ||
  1103.      strcmp(mai.category.name[8],"") ||
  1104.      strcmp(mai.category.name[9],"") ||
  1105.      strcmp(mai.category.name[10],"") ||
  1106.      strcmp(mai.category.name[11],"") ||
  1107.      strcmp(mai.category.name[12],"") ||
  1108.      strcmp(mai.category.name[13],"") ||
  1109.      strcmp(mai.category.name[14],"") ||
  1110.      strcmp(mai.category.name[15],"") ||
  1111.      mai.category.renamed[0] ||
  1112.      mai.category.renamed[1] ||
  1113.      mai.category.renamed[2] ||
  1114.      mai.category.renamed[3] ||
  1115.      (!mai.category.renamed[4]) ||
  1116.      mai.category.renamed[5] ||
  1117.      mai.category.renamed[6] ||
  1118.      mai.category.renamed[7] ||
  1119.      mai.category.renamed[8] ||
  1120.      mai.category.renamed[9] ||
  1121.      mai.category.renamed[10] ||
  1122.      mai.category.renamed[11] ||
  1123.      mai.category.renamed[12] ||
  1124.      mai.category.renamed[13] ||
  1125.      mai.category.renamed[14] ||
  1126.      mai.category.renamed[15] ||
  1127.      (mai.category.ID[0] != 0) ||
  1128.      (mai.category.ID[1] != 1) ||
  1129.      (mai.category.ID[2] != 2) ||
  1130.      (mai.category.ID[3] != 3) ||
  1131.      (mai.category.ID[4] != 17) ||
  1132.      (mai.category.ID[5] != 0) ||
  1133.      (mai.category.ID[6] != 0) ||
  1134.      (mai.category.ID[7] != 0) ||
  1135.      (mai.category.ID[8] != 0) ||
  1136.      (mai.category.ID[9] != 0) ||
  1137.      (mai.category.ID[10] != 0) ||
  1138.      (mai.category.ID[11] != 0) ||
  1139.      (mai.category.ID[12] != 0) ||
  1140.      (mai.category.ID[13] != 0) ||
  1141.      (mai.category.ID[14] != 0) ||
  1142.      (mai.category.ID[15] != 0) ||
  1143.      (mai.category.lastUniqueID != 17)  ||*/
  1144.      0
  1145.      ) {
  1146.      errors++;
  1147.      printf("4: unpack_ExpenseAppInfo generated incorrect information\n");
  1148.   }
  1149.   
  1150.   /* Packer should return necessary block length when no buffer is given */
  1151.   l = pack_ExpenseAppInfo(&mai, 0, 0);
  1152.   if (l != sizeof(ExpenseAppBlock)) {
  1153.     errors++;
  1154.     printf("5: pack_ExpenseAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(ExpenseAppBlock));
  1155.   }
  1156.   
  1157.   reset_block(target,8192);
  1158.  
  1159.   /* Packer should not pack when the block length is too small */
  1160.   l = pack_ExpenseAppInfo(&mai, target+128, 1);
  1161.   if (l != 0) {
  1162.     errors++;
  1163.     printf("6: pack_ExpenseAppInfo packed into too small buffer (got %d)\n", l);
  1164.   }
  1165.   
  1166.   /* Packer should not scribble on memory */
  1167.   if (check_block(7, target,8192, 128, 1, "pack_ExpenseAppInfo"))
  1168.     errors++;
  1169.  
  1170.   reset_block(target,8192);
  1171.  
  1172.   /* Packer should return length of data written */
  1173.   l = pack_ExpenseAppInfo(&mai, target+128, 8192-256);
  1174.   if (l != sizeof(ExpenseAppBlock)) {
  1175.     errors++;
  1176.     printf("8: pack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseAppBlock));
  1177.   }
  1178.  
  1179.   /* Packer should not scribble on memory */
  1180.   if (check_block(9, target,8192, 128, l, "pack_ExpenseAppInfo"))
  1181.     errors++;
  1182.     
  1183.   if (memcmp(target+128, ExpenseAppBlock, sizeof(ExpenseAppBlock))) {
  1184.     errors++;
  1185.     printf("10: pack_ExpenseAppInfo generated incorrect information. Got:\n");
  1186.     dumpdata(target+128, l);
  1187.     printf(" expected:\n");
  1188.     dumpdata(ExpenseAppBlock, sizeof(ExpenseAppBlock));
  1189.   }
  1190.     
  1191.   
  1192.   /* Unpacker should return count of bytes used */
  1193.   l = unpack_Expense(&m, ExpenseRecord, sizeof(ExpenseRecord)+10);
  1194.   if (l != sizeof(ExpenseRecord)) {
  1195.     errors++;
  1196.     printf("11: unpack_Expense returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseRecord));
  1197.   }
  1198.  
  1199.   if (
  1200. /*     (m.phonelabel[0] != 0) ||
  1201.      (m.phonelabel[1] != 1) ||
  1202.      (m.phonelabel[2] != 2) ||
  1203.      (m.phonelabel[3] != 3) ||
  1204.      (m.phonelabel[4] != 4) ||
  1205.      strcmp(m.entry[0],"Shaw") ||
  1206.      strcmp(m.entry[1],"Bernard") ||
  1207.      m.entry[2] ||
  1208.      m.entry[3] ||
  1209.      strcmp(m.entry[8],"None known") ||
  1210.      strcmp(m.entry[14],"C1") ||
  1211.      (m.whichphone != 1) ||*/
  1212.      0
  1213.      ) {
  1214.      errors++;
  1215.      printf("12: unpack_Expense generated incorrect information\n");
  1216.   }
  1217.   
  1218.   /* Packer should return necessary block length when no buffer is given */
  1219.   l = pack_Expense(&m, 0, 0);
  1220.   if (l != sizeof(ExpenseRecord)) {
  1221.     errors++;
  1222.     printf("13: pack_Expense returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(ExpenseRecord));
  1223.   }
  1224.   
  1225.   reset_block(target,8192);
  1226.  
  1227.   /* Packer should not pack when the block length is too small */
  1228.   l = pack_Expense(&m, target+128, 1);
  1229.   if (l != 0) {
  1230.     errors++;
  1231.     printf("14: pack_Expense packed into too small buffer (got %d)\n", l);
  1232.   }
  1233.   
  1234.   /* Packer should not scribble on memory */
  1235.   if (check_block(15, target, 8192, 128, 1, "pack_Expense"))
  1236.     errors++;
  1237.  
  1238.   reset_block(target,8192);
  1239.  
  1240.   /* Packer should return length of data written */
  1241.   l = pack_Expense(&m, target+128, 8192-256);
  1242.   if (l != sizeof(ExpenseRecord)) {
  1243.     errors++;
  1244.     printf("16: pack_Expense returned incorrect length (got %d, expected %d)\n", l, sizeof(ExpenseRecord));
  1245.   }
  1246.  
  1247.   /* Packer should not scribble on memory */
  1248.   if (check_block(17, target,8192, 128, l, "pack_Expense"))
  1249.     errors++;
  1250.     
  1251.   if (memcmp(target+128, ExpenseRecord, sizeof(ExpenseRecord))) {
  1252.     errors++;
  1253.     printf("18: pack_Expense generated incorrect information. Got:\n");
  1254.     dumpdata(target+128, l);
  1255.     printf(" expected:\n");
  1256.     dumpdata(ExpenseRecord, sizeof(ExpenseRecord));
  1257.   }
  1258.     
  1259.   printf("Expense packers test completed with %d error(s).\n", errors);
  1260.   
  1261.   return errors;
  1262. }
  1263.  
  1264. char MailAppBlock[18*16+1] = "\
  1265. \x00\x1f\x49\x6e\x62\x6f\x78\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1266. \x00\x00\x4f\x75\x74\x62\x6f\x78\x00\x00\x00\x00\x00\x00\x00\x00\
  1267. \x00\x00\x44\x65\x6c\x65\x74\x65\x64\x00\x00\x00\x00\x00\x00\x00\
  1268. \x00\x00\x46\x69\x6c\x65\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1269. \x00\x00\x44\x72\x61\x66\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1270. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1271. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1272. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1273. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1274. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1275. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1276. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1277. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1278. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1279. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1280. \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
  1281. \x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\
  1282. \x0e\x0f\x0f\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x01\x20\
  1283. \x00";
  1284.  
  1285. char MailRecord[1*16+2] = "\
  1286. \x00\x00\x00\x00\x78\x00\x43\x00\x00\x61\x00\x62\x00\x00\x00\x00\
  1287. \x44\x00"; /*\x27";  This byte seems to be spurious */
  1288.  
  1289. char MailSigPreference[3] = "\
  1290. \x61\x62\x00";
  1291.  
  1292. char MailSyncPreference[13] = "\
  1293. \x02\x01\x00\x00\x17\x70\x61\x74\x00\x6c\x64\x00\x00";
  1294.  
  1295. int test_mail() {
  1296.   struct MailAppInfo mai;
  1297.   struct Mail m;
  1298.   struct MailSyncPref s1;
  1299.   struct MailSignaturePref s2;
  1300.   int l;
  1301.   int errors=0;
  1302.   
  1303.   /* Unpacker should return count of bytes used */
  1304.   l = unpack_MailAppInfo(&mai, MailAppBlock, sizeof(MailAppBlock)+10);
  1305.   if (l != sizeof(MailAppBlock)) {
  1306.     errors++;
  1307.     printf("1: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MailAppBlock));
  1308.   }
  1309.  
  1310.   /* Unpacker should return count of bytes used */
  1311.   l = unpack_MailAppInfo(&mai, MailAppBlock, sizeof(MailAppBlock)+1);
  1312.   if (l != sizeof(MailAppBlock)) {
  1313.     errors++;
  1314.     printf("2: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MailAppBlock));
  1315.   }
  1316.  
  1317.   /* Unpacker should return failure if the block is too small to contain data */
  1318.   /*l = unpack_MailAppInfo(&mai, MailAppBlock, sizeof(MailAppBlock)-10);
  1319.   if (l != 0) {
  1320.     errors++;
  1321.     printf("2: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", l, 0);
  1322.   }*/
  1323.  
  1324.   /* Unpacker should return count of bytes used */
  1325.   l = unpack_MailAppInfo(&mai, MailAppBlock, sizeof(MailAppBlock));
  1326.   if (l != sizeof(MailAppBlock)) {
  1327.     errors++;
  1328.     printf("3: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MailAppBlock));
  1329.   }
  1330.  
  1331.   
  1332.   if (
  1333. /*     strcmp(mai.category.name[0],"Unfiled") ||
  1334.      strcmp(mai.category.name[1],"Business") ||
  1335.      strcmp(mai.category.name[2],"Personal") ||
  1336.      strcmp(mai.category.name[3],"QuickList") ||
  1337.      strcmp(mai.category.name[4],"Foo") ||
  1338.      strcmp(mai.category.name[5],"") ||
  1339.      strcmp(mai.category.name[6],"") ||
  1340.      strcmp(mai.category.name[7],"") ||
  1341.      strcmp(mai.category.name[8],"") ||
  1342.      strcmp(mai.category.name[9],"") ||
  1343.      strcmp(mai.category.name[10],"") ||
  1344.      strcmp(mai.category.name[11],"") ||
  1345.      strcmp(mai.category.name[12],"") ||
  1346.      strcmp(mai.category.name[13],"") ||
  1347.      strcmp(mai.category.name[14],"") ||
  1348.      strcmp(mai.category.name[15],"") ||
  1349.      mai.category.renamed[0] ||
  1350.      mai.category.renamed[1] ||
  1351.      mai.category.renamed[2] ||
  1352.      mai.category.renamed[3] ||
  1353.      (!mai.category.renamed[4]) ||
  1354.      mai.category.renamed[5] ||
  1355.      mai.category.renamed[6] ||
  1356.      mai.category.renamed[7] ||
  1357.      mai.category.renamed[8] ||
  1358.      mai.category.renamed[9] ||
  1359.      mai.category.renamed[10] ||
  1360.      mai.category.renamed[11] ||
  1361.      mai.category.renamed[12] ||
  1362.      mai.category.renamed[13] ||
  1363.      mai.category.renamed[14] ||
  1364.      mai.category.renamed[15] ||
  1365.      (mai.category.ID[0] != 0) ||
  1366.      (mai.category.ID[1] != 1) ||
  1367.      (mai.category.ID[2] != 2) ||
  1368.      (mai.category.ID[3] != 3) ||
  1369.      (mai.category.ID[4] != 17) ||
  1370.      (mai.category.ID[5] != 0) ||
  1371.      (mai.category.ID[6] != 0) ||
  1372.      (mai.category.ID[7] != 0) ||
  1373.      (mai.category.ID[8] != 0) ||
  1374.      (mai.category.ID[9] != 0) ||
  1375.      (mai.category.ID[10] != 0) ||
  1376.      (mai.category.ID[11] != 0) ||
  1377.      (mai.category.ID[12] != 0) ||
  1378.      (mai.category.ID[13] != 0) ||
  1379.      (mai.category.ID[14] != 0) ||
  1380.      (mai.category.ID[15] != 0) ||
  1381.      (mai.category.lastUniqueID != 17)  ||*/
  1382.      0
  1383.      ) {
  1384.      errors++;
  1385.      printf("4: unpack_MailAppInfo generated incorrect information\n");
  1386.   }
  1387.   
  1388.   /* Packer should return necessary block length when no buffer is given */
  1389.   l = pack_MailAppInfo(&mai, 0, 0);
  1390.   if (l != sizeof(MailAppBlock)) {
  1391.     errors++;
  1392.     printf("5: pack_MailAppInfo returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MailAppBlock));
  1393.   }
  1394.   
  1395.   reset_block(target,8192);
  1396.  
  1397.   /* Packer should not pack when the block length is too small */
  1398.   l = pack_MailAppInfo(&mai, target+128, 1);
  1399.   if (l != 0) {
  1400.     errors++;
  1401.     printf("6: pack_MailAppInfo packed into too small buffer (got %d)\n", l);
  1402.   }
  1403.   
  1404.   /* Packer should not scribble on memory */
  1405.   if (check_block(7, target,8192, 128, 1, "pack_MailAppInfo"))
  1406.     errors++;
  1407.  
  1408.   reset_block(target,8192);
  1409.  
  1410.   /* Packer should return length of data written */
  1411.   l = pack_MailAppInfo(&mai, target+128, 8192-256);
  1412.   if (l != sizeof(MailAppBlock)) {
  1413.     errors++;
  1414.     printf("8: pack_MailAppInfo returned incorrect length (got %d, expected %d)\n", l, sizeof(MailAppBlock));
  1415.   }
  1416.  
  1417.   /* Packer should not scribble on memory */
  1418.   if (check_block(9, target,8192, 128, l, "pack_MailAppInfo"))
  1419.     errors++;
  1420.     
  1421.   if (memcmp(target+128, MailAppBlock, sizeof(MailAppBlock))) {
  1422.     errors++;
  1423.     printf("10: pack_MailAppInfo generated incorrect information. Got:\n");
  1424.     dumpdata(target+128, l);
  1425.     printf(" expected:\n");
  1426.     dumpdata(MailAppBlock, sizeof(MailAppBlock));
  1427.   }
  1428.     
  1429.   
  1430.   /* Unpacker should return count of bytes used */
  1431.   l = unpack_Mail(&m, MailRecord, sizeof(MailRecord)+10);
  1432.   if (l != sizeof(MailRecord)) {
  1433.     errors++;
  1434.     printf("11: unpack_Mail returned incorrect length (got %d, expected %d)\n", l, sizeof(MailRecord));
  1435.   }
  1436.  
  1437.   if (
  1438. /*     (m.phonelabel[0] != 0) ||
  1439.      (m.phonelabel[1] != 1) ||
  1440.      (m.phonelabel[2] != 2) ||
  1441.      (m.phonelabel[3] != 3) ||
  1442.      (m.phonelabel[4] != 4) ||
  1443.      strcmp(m.entry[0],"Shaw") ||
  1444.      strcmp(m.entry[1],"Bernard") ||
  1445.      m.entry[2] ||
  1446.      m.entry[3] ||
  1447.      strcmp(m.entry[8],"None known") ||
  1448.      strcmp(m.entry[14],"C1") ||
  1449.      (m.whichphone != 1) ||*/
  1450.      0
  1451.      ) {
  1452.      errors++;
  1453.      printf("12: unpack_Mail generated incorrect information\n");
  1454.   }
  1455.   
  1456.   /* Packer should return necessary block length when no buffer is given */
  1457.   l = pack_Mail(&m, 0, 0);
  1458.   if (l != sizeof(MailRecord)) {
  1459.     errors++;
  1460.     printf("13: pack_Mail returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MailRecord));
  1461.   }
  1462.   
  1463.   reset_block(target,8192);
  1464.  
  1465.   /* Packer should not pack when the block length is too small */
  1466.   l = pack_Mail(&m, target+128, 1);
  1467.   if (l != 0) {
  1468.     errors++;
  1469.     printf("14: pack_Mail packed into too small buffer (got %d)\n", l);
  1470.   }
  1471.   
  1472.   /* Packer should not scribble on memory */
  1473.   if (check_block(15, target, 8192, 128, 1, "pack_Mail"))
  1474.     errors++;
  1475.  
  1476.   reset_block(target,8192);
  1477.  
  1478.   /* Packer should return length of data written */
  1479.   l = pack_Mail(&m, target+128, 8192-256);
  1480.   if (l != sizeof(MailRecord)) {
  1481.     errors++;
  1482.     printf("16: pack_Mail returned incorrect length (got %d, expected %d)\n", l, sizeof(MailRecord));
  1483.   }
  1484.  
  1485.   /* Packer should not scribble on memory */
  1486.   if (check_block(17, target,8192, 128, l, "pack_Mail"))
  1487.     errors++;
  1488.     
  1489.   if (memcmp(target+128, MailRecord, sizeof(MailRecord))) {
  1490.     errors++;
  1491.     printf("18: pack_Mail generated incorrect information. Got:\n");
  1492.     dumpdata(target+128, l);
  1493.     printf(" expected:\n");
  1494.     dumpdata(MailRecord, sizeof(MailRecord));
  1495.   }
  1496.  
  1497.  
  1498.   /* Unpacker should return count of bytes used */
  1499.   l = unpack_MailSyncPref(&s1, MailSyncPreference, sizeof(MailSyncPreference)+10);
  1500.   if (l != sizeof(MailSyncPreference)) {
  1501.     errors++;
  1502.     printf("19: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1503.   }
  1504.  
  1505.   /* Unpacker should return count of bytes used */
  1506.   l = unpack_MailSyncPref(&s1, MailSyncPreference, sizeof(MailSyncPreference)+1);
  1507.   if (l != sizeof(MailSyncPreference)) {
  1508.     errors++;
  1509.     printf("20: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1510.   }
  1511.  
  1512.   /* Unpacker should return count of bytes used */
  1513.   l = unpack_MailSyncPref(&s1, MailSyncPreference, sizeof(MailSyncPreference));
  1514.   if (l != sizeof(MailSyncPreference)) {
  1515.     errors++;
  1516.     printf("21: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1517.   }
  1518.  
  1519.   if (
  1520. /*     (m.phonelabel[0] != 0) ||
  1521.      (m.phonelabel[1] != 1) ||
  1522.      (m.phonelabel[2] != 2) ||
  1523.      (m.phonelabel[3] != 3) ||
  1524.      (m.phonelabel[4] != 4) ||
  1525.      strcmp(m.entry[0],"Shaw") ||
  1526.      strcmp(m.entry[1],"Bernard") ||
  1527.      m.entry[2] ||
  1528.      m.entry[3] ||
  1529.      strcmp(m.entry[8],"None known") ||
  1530.      strcmp(m.entry[14],"C1") ||
  1531.      (m.whichphone != 1) ||*/
  1532.      0
  1533.      ) {
  1534.      errors++;
  1535.      printf("22: unpack_MailSyncPref generated incorrect information\n");
  1536.   }
  1537.   
  1538.   /* Packer should return necessary block length when no buffer is given */
  1539.   l = pack_MailSyncPref(&s1, 0, 0);
  1540.   if (l != sizeof(MailSyncPreference)) {
  1541.     errors++;
  1542.     printf("23: pack_MailSyncPref returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1543.   }
  1544.   
  1545.   reset_block(target,8192);
  1546.  
  1547.   /* Packer should not pack when the block length is too small */
  1548.   l = pack_MailSyncPref(&s1, target+128, 1);
  1549.   if (l != 0) {
  1550.     errors++;
  1551.     printf("24: pack_MailSyncPref packed into too small buffer (got %d)\n", l);
  1552.   }
  1553.   
  1554.   /* Packer should not scribble on memory */
  1555.   if (check_block(25, target, 8192, 128, 1, "pack_MailSyncPref"))
  1556.     errors++;
  1557.  
  1558.   reset_block(target,8192);
  1559.  
  1560.   /* Packer should return length of data written */
  1561.   l = pack_MailSyncPref(&s1, target+128, 8192-256);
  1562.   if (l != sizeof(MailSyncPreference)) {
  1563.     errors++;
  1564.     printf("26: pack_MailSyncPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1565.   }
  1566.  
  1567.   /* Packer should not scribble on memory */
  1568.   if (check_block(27, target,8192, 128, l, "pack_Mail"))
  1569.     errors++;
  1570.     
  1571.   if (memcmp(target+128, MailSyncPreference, sizeof(MailSyncPreference))) {
  1572.     errors++;
  1573.     printf("28: pack_MailSyncPref generated incorrect information. Got:\n");
  1574.     dumpdata(target+128, l);
  1575.     printf(" expected:\n");
  1576.     dumpdata(MailSyncPreference, sizeof(MailSyncPreference));
  1577.   }
  1578.  
  1579.  
  1580.   /* Unpacker should return count of bytes used */
  1581.   l = unpack_MailSignaturePref(&s2, MailSigPreference, sizeof(MailSigPreference)+10);
  1582.   if (l != sizeof(MailSigPreference)) {
  1583.     errors++;
  1584.     printf("29: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1585.   }
  1586.  
  1587.   /* Unpacker should return count of bytes used */
  1588.   l = unpack_MailSignaturePref(&s2, MailSigPreference, sizeof(MailSigPreference)+1);
  1589.   if (l != sizeof(MailSigPreference)) {
  1590.     errors++;
  1591.     printf("30: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1592.   }
  1593.   
  1594.   /* Unpacker should return count of bytes used */
  1595.   l = unpack_MailSignaturePref(&s2, MailSigPreference, sizeof(MailSigPreference));
  1596.   if (l != sizeof(MailSigPreference)) {
  1597.     errors++;
  1598.     printf("31: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSyncPreference));
  1599.   }
  1600.  
  1601.   if (
  1602. /*     (m.phonelabel[0] != 0) ||
  1603.      (m.phonelabel[1] != 1) ||
  1604.      (m.phonelabel[2] != 2) ||
  1605.      (m.phonelabel[3] != 3) ||
  1606.      (m.phonelabel[4] != 4) ||
  1607.      strcmp(m.entry[0],"Shaw") ||
  1608.      strcmp(m.entry[1],"Bernard") ||
  1609.      m.entry[2] ||
  1610.      m.entry[3] ||
  1611.      strcmp(m.entry[8],"None known") ||
  1612.      strcmp(m.entry[14],"C1") ||
  1613.      (m.whichphone != 1) ||*/
  1614.      0
  1615.      ) {
  1616.      errors++;
  1617.      printf("32: unpack_MailSyncPref generated incorrect information\n");
  1618.   }
  1619.   
  1620.   /* Packer should return necessary block length when no buffer is given */
  1621.   l = pack_MailSignaturePref(&s2, 0, 0);
  1622.   if (l != sizeof(MailSigPreference)) {
  1623.     errors++;
  1624.     printf("33: pack_MailSignaturePref returned incorrect allocation length (got %d, expected %d)\n", l, sizeof(MailSigPreference));
  1625.   }
  1626.   
  1627.   reset_block(target,8192);
  1628.  
  1629.   /* Packer should not pack when the block length is too small */
  1630.   l = pack_MailSignaturePref(&s2, target+128, 1);
  1631.   if (l != 0) {
  1632.     errors++;
  1633.     printf("34: pack_MailSignaturePref packed into too small buffer (got %d)\n", l);
  1634.   }
  1635.   
  1636.   /* Packer should not scribble on memory */
  1637.   if (check_block(35, target, 8192, 128, 1, "pack_MailSyncPref"))
  1638.     errors++;
  1639.  
  1640.   reset_block(target,8192);
  1641.  
  1642.   /* Packer should return length of data written */
  1643.   l = pack_MailSignaturePref(&s2, target+128, 8192-256);
  1644.   if (l != sizeof(MailSigPreference)) {
  1645.     errors++;
  1646.     printf("36: pack_MailSignaturePref returned incorrect length (got %d, expected %d)\n", l, sizeof(MailSigPreference));
  1647.   }
  1648.  
  1649.   /* Packer should not scribble on memory */
  1650.   if (check_block(37, target,8192, 128, l, "pack_Mail"))
  1651.     errors++;
  1652.     
  1653.   if (memcmp(target+128, MailSigPreference, sizeof(MailSigPreference))) {
  1654.     errors++;
  1655.     printf("38: pack_MailSignaturePref generated incorrect information. Got:\n");
  1656.     dumpdata(target+128, l);
  1657.     printf(" expected:\n");
  1658.     dumpdata(MailSigPreference, sizeof(MailSigPreference));
  1659.   }
  1660.     
  1661.   printf("Mail packers test completed with %d error(s).\n", errors);
  1662.   
  1663.   return errors;
  1664. }
  1665.  
  1666.  
  1667. int main(int argc, char *argv[])
  1668. {
  1669.   seed = time(0) & 0xff; /* Make scribble checker use a random check value */
  1670.   target = malloc(8192);
  1671.   targetlen = 8192;
  1672.   
  1673.   test_memo();
  1674.   test_address();
  1675.   test_appointment();
  1676.   test_todo();
  1677.   test_expense();
  1678.   test_mail();
  1679.   return 0;
  1680. }
  1681.